package com.zhanglinwei.test.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhanglinwei.openApiClient.model.request.ExampleGetByCodeListRequest;
import com.zhanglinwei.openApiClient.model.request.ExampleGetByCodeRequest;
import com.zhanglinwei.openApiClient.model.response.api.ExampleGetByCodeResponse;
import com.zhanglinwei.openApiServer.annotation.OpenApi;
import com.zhanglinwei.openApiServer.annotation.OpenApiReference;
import com.zhanglinwei.test.mapper.ToolsMapper;
import com.zhanglinwei.test.model.entity.ToolsDO;
import com.zhanglinwei.test.model.request.ToolsRequest;
import com.zhanglinwei.test.service.OpenService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Slf4j
@OpenApiReference
public class OpenServiceImpl implements OpenService {

    @Resource
    private ToolsMapper toolsMapper;

    @Override
    @OpenApi("list.user.queryList")
    public List<ToolsDO> queryToolList() {
        return toolsMapper.selectList(null);
    }

    @Override
    @OpenApi("xx.xx.queryByCode")
    public List<ToolsDO> queryByCode(String code) {
        return toolsMapper.selectList(Wrappers.<ToolsDO>lambdaQuery()
                .eq(ToolsDO::getCode, code)
        );
    }

    @Override
    @OpenApi("xx.xx.queryByObj")
    public List<ToolsDO> queryByObj(ToolsRequest request) {
        return toolsMapper.selectList(Wrappers.<ToolsDO>lambdaQuery()
                .eq(ToolsDO::getCode, request.getCode())
                .eq(ToolsDO::getMenuId, request.getMenuId())
        );
    }

    @OpenApi("xx.one.queryByObj")
    public List<ToolsDO> oneQueryByObj(ToolsRequest request) {
        log.info("xx.one.queryByObj ==> {}", JSON.toJSONString(request));
        return null;
    }

    @OpenApi("xxx.example.getByCode")
    public Object exampleGetByCode(ExampleGetByCodeRequest request) {
        ExampleGetByCodeResponse.ResponseContent response = new ExampleGetByCodeResponse.ResponseContent();
        response.setCode("stringValue");
        response.setName("stringValue");
        return response;
    }

    @OpenApi("xxx.example.getByCodeList")
    public Object exampleGetByCodeList(ExampleGetByCodeListRequest request) {
        ExampleGetByCodeResponse.ResponseContent response = new ExampleGetByCodeResponse.ResponseContent();
        response.setCode("stringValue");
        response.setName("stringValue");
        return Collections.singletonList(response);
    }




}
